<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class ZoneRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $editRules = [
            'id'       => 'required|numeric',
            'name'     => 'required',
            'alpha'    => 'required',
            'level'    => 'required|numeric',
            'pinyin'   => 'required|numeric',
            'upid'     => 'sometimes|numeric',
            'is_store' => 'required|boolean',
        ];

        $createRules = [
            'name'     => 'required',
            'alpha'    => 'required',
            'level'    => 'required|numeric',
            'pinyin'   => 'required|numeric',
            'upid'     => 'sometimes|numeric',
            'is_store' => 'required|boolean',
        ];

//        return array();

        $data = Request::all();
        //如果是编辑
        if ($data['formType'] == 'edit') {
            return $editRules;
        }
        //如果是创建
        if ($data['formType'] == 'create') {
            return $createRules;
        }
    }

    public function attributes()
    {
        $attributes = array(
            'name'     => '城市名称',
            'alpha'    => '城市首字母',
            'level'    => '级别',
            'pinyin'   => '全拼',
            'upid'     => '父地区',
            'is_store' => '是否有门店 ',
        );

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'numeric'           => ':attribute必须为数字',
            'is_store.boolean'         => ':attribute必须为有、暂无中的一种',
        ];

        return $messages;
    }
}
